#ifndef MODBUS_TCP_SLAVE_H
#define MODBUS_TCP_SLAVE_H

#include <QMainWindow>
#include <QStandardItemModel>
#include <QModbusTcpServer>

namespace Ui {
class modbus_tcp_slave;
}

class modbus_tcp_slave : public QMainWindow
{
    Q_OBJECT

public:
    modbus_tcp_slave(QWidget *parent = nullptr);
    ~modbus_tcp_slave();

private slots:
    void on_connectButton_clicked();
    void updateRegisterValue(const QModelIndex &topLeft, const QModelIndex &bottomRight);
    void handleDeviceError(QModbusDevice::Error error);

private:
    Ui::modbus_tcp_slave *ui;
    QModbusTcpServer *modbusDevice = nullptr;
    QStandardItemModel *registersModel = nullptr;
    void setupModbusSlave();
    void setupRegistersTable();
    void updateUiState(bool connected);

    bool isValidIp(const QString &ipString);
};

#endif // MODBUS_TCP_SLAVE_H